<!DOCTYPE html>
<html class="x-admin-sm">
    
    <head>
        <meta charset="UTF-8">
        <title>欢迎页面-X-admin2.2</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="./css/font.css">
        <link rel="stylesheet" href="./css/xadmin.css">
        <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
        <script src="./lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="./js/xadmin.js"></script>
    </head>
    <body>
        <div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">首页</a>
                <a href="">订单管理</a>
                <a>
                    <cite>订单列表</cite></a>
            </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
                <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
            </a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <form class="layui-form layui-col-space5">
                                <div class="layui-input-inline layui-show-xs-block">
                                    <input type="text" name="username" placeholder="请输入用户名" autocomplete="off" class="layui-input" id="searchUsername"></div>
                                <div class="layui-input-inline layui-show-xs-block">
                                    <button class="layui-btn" lay-submit="" lay-filter="sreach" id="search" onclick="play(1)">
                                        <i class="layui-icon">&#xe615;</i></button>
                                </div>
                            </form>
                        </div>
                        <div class="layui-card-body layui-table-body layui-table-main">
                            <table class="layui-table layui-form">
                                <thead>
                                <tr>
                                    <th>
                                        <input type="checkbox" lay-filter="checkall" class="checkbox" lay-skin="primary">
                                    </th>
                                    <th>订单号</th>
                                    <th>用户名</th>
                                    <th>付款金额</th>
                                    <th>订单时间</th>
                                    <th>房间号</th>
                                    <th>房间类型</th>
                                    <th>酒店名</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody id="ttable">

                                </tbody>
                            </table>
                        </div>
                        <div class="layui-card-body ">
                            <div class="page">
                                <div id="page">

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
                <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
                <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
            </div>
        </script>
    </body>
    <script>
        var orderId;
        play(1);
        function play(current) {
            $("#ttable").empty();
            $("#page").empty();
            $.ajax({
                type: "POST",
                url: "OrderList",
                contentType: "application/json;charset=UTF-8",
                dataType: "json",
                data: JSON.stringify({
                    flag: '1',
                    "currentPage":current,
                    "username": $("#SearchUsername").val(),
                }),
                success: function (data) {
                    orderId=data.orderId;
                    var UserInfoList = "";
                    $(data.list).each(function (index, item) {
                        UserInfoList = "<tr id='userinfomation'>\n" +
                            "<td>\n" +
                            "  <input type=\"checkbox\" name=\"id\" value=\"1\"   lay-skin=\"primary\" id=" + item.orderId + " class=\"checkbox1\">\n" +
                            "</td>\n" +
                            "<td>" + item.orderId + "</td>\n"+
                            "<td>" + item.username + "</td>\n" +
                            "<td>" + item.totalmoney + "</td>\n" +
                            "<td>" + item.generationTime + "</td>\n" +
                            "<td>" + item.roomId + "</td>\n" +
                            "<td>" + item.roomType + "</td>\n" +
                            "<td>" + item.hotelName + "</td>\n" +
                            "<td><input type='button' value='删除' class='delete' name='"+item.orderId+"' id='"+item.roomId+"'></td>" +
                            "</tr>";
                        $("#ttable").append(UserInfoList);
                    })
                    if (data.pageNum==1){
                        $("#page").append($("<a class=\"prev\">&lt;&lt;</a>"));
                    }else {
                        $("#page").append($("<a class=\"prev\" onclick='play("+data.prePage+")'>&lt;&lt;</a>"));
                    }
                    for (var i=1;i<=data.lastPage;i++){
                        if (data.pageNum==i){
                            $("#page").append($(" <span onclick='play("+i+")' class=\"current\">"+i+"</span>"))
                        }else {
                            $("#page").append($("<a class=\"num\" onclick='play("+i+")'>"+i+"</a>"))
                        }
                    }
                    if (data.pageNum==data.lastPage){
                        $("#page").append($("<a class=\"next\">&gt;&gt;</a>"));
                    } else {
                        $("#page").append($("<a class=\"next\" onclick='play("+data.nextPage+")'>&gt;&gt;</a>"));
                    }
                },
                error: function (data) {
                    alert(111);
                    console.error(data+"******************");
                }
            })
        }


        $(document).on("click",".delete",function(){
            //1. 获取id值
            srcElement = window.event.srcElement;
            var did=srcElement.name;
            var rid=srcElement.id;
            $.ajax({
                type: 'POST',
                url: "delOrder",
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify({
                    "orderId": did,
                    "roomId": rid
                }),
                dataType: "json",
                success: function (data) {
                    if (data) {
                        window.location.reload();
                    } else {
                        alert("删除失败")
                    }
                },
                error: function (data) {
                    console.error("111" + data);
                }
            })

        })
    </script>


</html>